import java.awt.*; import java.awt.event.*; class MyFrame extends Frame implements ActionListener { TextField t1,t2; Button b1; public MyFrame() { setLayout(new FlowLayout()); t1=new TextField(10); t2=new TextField(10); b1=new Button("Exchange"); b1.addActionListener(this); add(t1); add(b1); add(t2); } public void actionPerformed(ActionEvent e) { String d1=t1.getText(); String d2=t2.getText(); t1.setText(d2); t2.setText(d1); } } class demo { public static void main(String args[]) { MyFrame frm=new MyFrame(); frm.setVisible(true); frm.setSize(400,300); } }
import java.awt.*; import java.awt.event.*; class MyFrame extends Frame implements ActionListener { TextField t1; Button b1,b2; public MyFrame() { setLayout(new FlowLayout()); t1=new TextField(10); b1=new Button("Increment"); b2=new Button("Decrement"); b1.addActionListener(this); b2.addActionListener(this); add(b1); add(t1); add(b2); } public void actionPerformed(ActionEvent e) { int n=Integer.parseInt(t1.getText()); if(e.getSource()==b1) n=n+1; else if(e.getSource()==b2) n=n-1; t1.setText(String.valueOf(n)); } } class demo { public static void main(String args[]) { MyFrame frm=new MyFrame(); frm.setSize(400,300); frm.setVisible(true); } }